//
//  EventDetailViewCell.m
//  Runone
//
//  Created by runone02 on 16/12/22.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "EventDetailViewCell.h"
#import "UIImageView+WebCache.h"
#import "ROPhotoBrowser.h"
#import "SDImageCache.h"

@interface EventDetailViewCell () <ROPhotoBrowserDelegate>
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *recorderLabel;
@property (weak, nonatomic) IBOutlet UILabel *dealDetailLabel;
@property (weak, nonatomic) IBOutlet UIView *picContainerView;
@property (weak, nonatomic) IBOutlet UIView *lineView;

@end


@implementation EventDetailViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    _dealDetailLabel.hidden = NO;
    _picContainerView.hidden = NO;
    for (int i = 0; i < 5; i ++) {
        for (int i = 0; i < 5; i ++) {
            UIImageView *imageV = _picContainerView.subviews[i];
            imageV.hidden = NO;
        }
    }
}

- (void)setLModel:(EventDealListModel *)lModel {
    _lModel = lModel;
    _timeLabel.text = _lModel.DealTime;
    _recorderLabel.text = _lModel.UpdateUserName;
    if (_lModel.DealDetail) {
        _dealDetailLabel.hidden = NO;
        _dealDetailLabel.text   = _lModel.DealDetail;
    }else {
        _dealDetailLabel.hidden = YES;
    }
    if (_lModel.PicturePath.count > 0) {
        _picContainerView.hidden = NO;
        [self configPic]; //设置图片
    }else {
        _picContainerView.hidden = YES;
    }
}

- (void)configPic {
    for (int i = 0; i < _lModel.PicturePath.count; i++) {
        UIImageView *imgV = _picContainerView.subviews[i];
        NSURL *picUrl     = [NSURL URLWithString:_lModel.PicturePath[i]];
        [imgV sd_setImageWithURL:picUrl];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView:)];
        [imgV addGestureRecognizer:tap];
    }
}

#pragma mark - tap手势
- (void)tapImageView:(UITapGestureRecognizer *)tap {
    UIView *imageView = tap.view;
    ROPhotoBrowser *browser   = [[ROPhotoBrowser alloc] init];
    browser.isAnnimation      = YES;
    browser.currentImageIndex = imageView.tag;
    browser.sourceImagesContainerView = self;
    browser.imageCount = _lModel.PicturePath.count;
    browser.delegate   = self;
    [browser show];
}

-(void)prepareForReuse {
    [super prepareForReuse];
    _picContainerView.hidden = NO;
    for (int i = 0; i < 5; i ++) {
        UIImageView *imageV = _picContainerView.subviews[i];
        imageV.hidden = NO;
    }
    _dealDetailLabel.hidden = NO;
    [[SDImageCache sharedImageCache] clearMemory];
}

-(void)dealloc {
    [[SDImageCache sharedImageCache] clearMemory];
}

@end
